package util

import (
	"fmt"
	"math/rand"
	"time"

	"gitee.com/k-ayaka/et-userserver/po"
	"gitee.com/k-ayaka/std-go/crypto"
)

func GenerateToken(id int) string {
	timestamp := time.Now().Format(time.RFC3339)
	token := fmt.Sprintf("%s%d%d", timestamp, rand.Int(), id)
	return crypto.Md5EncryptToHexUpper(token)
}

func MatchPassword(psw string, user *po.User) bool {
	return crypto.Md5EncryptToHexUpper(psw) == user.Password
}
